#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <stdio.h>
#include <string.h>
#include <QFileDialog>
#include "glrenderer.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);   
    m_GLRenderer = new GLRenderer;
    m_LightDialog = new LightDialog(this);

    m_Filename = "";

    connect(ui->actionOpen_OBJ, SIGNAL(triggered()), SLOT(dialogOpenOBJ()));
    connect(ui->actionExport_AM, SIGNAL(triggered()), SLOT(dialogExportAM()));
    connect(ui->actionShow_LightsDialog, SIGNAL(triggered()), m_LightDialog, SLOT(show()));
    connect(ui->zoomSlider, SIGNAL(valueChanged(int)), m_GLRenderer, SLOT(zoom(int)));

    connect(m_LightDialog, SIGNAL(updateLightPos(float,float,float)),
            m_GLRenderer, SLOT(setLightPos(float,float,float)));

    ui->horizontalLayout_2->addWidget(m_GLRenderer);
}

MainWindow::~MainWindow()
{
    delete ui;
    delete m_GLRenderer;
}

void MainWindow::displayModel(model * m)
{
    m_GLRenderer->setModel(m);
}

void MainWindow::dialogOpenOBJ()
{
    m_Filename = QFileDialog::getOpenFileName(this, tr("Open File"), tr("/home/jewagenaar/"), tr("*.obj"));
    emit(openOBJ(m_Filename));
}

void MainWindow::dialogExportAM()
{    
    m_Filename = QFileDialog::getSaveFileName(this, tr("Export Model"), tr("/home/jewagenaar/"), tr("*.am"));
    emit(exportAM(m_Filename));
}
